package com.example.consumer_rocketmq.controller;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
@RestController
@Component
@RocketMQMessageListener(topic = "redisTopic",consumerGroup = "redis-consumer-group")
public class RedisConsumer implements RocketMQListener<String> {
    final String key="key1";
    @Resource
    RedisTemplate redisTemplate;

    @Override
    public void onMessage(String s) {
        if (s!=null){
            System.out.println("消费redis");
            redisTemplate.opsForValue().set(key,s);
        }
    }
    @GetMapping("/getMsg")
    public Object getMsg(){
        Object value = redisTemplate.opsForValue().get(key);
        return value;
    }
}
